<?php
/**
 * @desc access for Oracle Database
 * @author HoangNV2
 */
class SysOracleSql {
	public $config = array();
	public $conn = NULL;
	public $sql = '';
	public $recordset;
	public $result;
	public $oid;	// last insert id
	public $connection = NULL;

	public function __construct() {

	}
	
	/**
	 * use oci_connect()
	 * @param $host
	 * @param $port
	 * @param $dbname
	 * @param $user
	 * @param $pass
	 * @return $conn
	 */
	function connect ($host='localhost', $port='5432', $dbname='', $user='', $pass='') {
		$host = $this->config['host'];
		$user = $this->config['username'];
		$pass = $this->config['password'];
		$port = $this->config['port'];
		$dbname = $this->config['dbname'];
		
		if (!function_exists('oci_connect')) $this->exceptionError('Do not support database oracle');
		
		$this->conn = @oci_connect($user,$pass,$host.':'.$port.'/'.$dbname) OR $this->exceptionError(oci_error());
	}
	
	/**
	 * @return print error
	 */
	public function exceptionError ($msg, $act='') {
		if ($act == 'ROLLBACK') {
			@oci_rollback($this->conn);
		}
		throw new SysExceptionModel($msg);
	}

	/**
	 * @desc close connection
	 */
	public function __destruct () {
		// Close this connection
		@oci_close($this->conn);
	}
}